<template>
  <div class="swiper-container">
    <div class="swiper-wrapper">
      <div class="swiper-slide" v-for="(item, index) in DateList" :key="index">
        {{ item.date }}
      </div>
    </div>
    <!-- 如果不需要以下功能，注释即可 -->
    <!-- 如果需要分页器 -->
    <!-- <div class="swiper-pagination"></div> -->

    <!-- 如果需要导航按钮 -->
    <!-- <div class="swiper-button-prev"></div> -->
    <!-- <div class="swiper-button-next"></div> -->

    <!-- 如果需要滚动条 -->
    <!-- <div class="swiper-scrollbar"></div> -->
  </div>
</template>

<script>
import { IdeaDate } from "@/api/request";
import Swiper from "swiper";
import "swiper/css/swiper.min.css";

export default {
  name: "IdeaDateView",
  data() {
    return {
      NewDate: "",
      DateList: [],
    };
  },
  methods: {
    GetSwiper() {
      new Swiper(".swiper-container", {
        effect: "coverflow",
        // 显示的页数
        slidesPerView: 1,
        // 是否开启阴影
        slideShadows: true,
        coverflowEffect: {
          rotate: 30,
          stretch: 1,
          depth: 8,
          modifier: 1,
          slideShadows: true,
        },
       on: {
          // 用箭头函数指向vue实例 
          //swiper本身又是定义在vue实例上的 
          // 所以可以 找到他 再获取他身上的属性
          touchEnd: () => {
            console.log(this);
            console.log(this.$el.swiper);
            if (this.$el.swiper.translate < -1735) {
              console.log("小于拉");
            }
            // 移动距离
            console.log(this.$el.swiper.translate);
            // 移动下标
            console.log(this.$el.swiper.activeIndex);
          },
        },
        // on: {
        //   touchEnd: function () {
        //     //你的事件
        //     // this.tranFromIndex++;
        //     if (this.translate < -1735) {
        //       console.log("小于拉");
        //     }
        //     // 移动距离
        //     console.log(this.translate);
        //     // 移动下标
        //     console.log(this.activeIndex);
        //   },
        // },
        // loop: true, // 循环模式选项
        // slidesPerView: 1,
        // centeredSlides: true,
        // centeredSlidesBounds: true,
        // // 如果需要分页器
        // pagination: {
        //   el: ".swiper-pagination",
        // },
      });
    },
  },
  mounted() {
    // 传过来的date日期
    this.NewDate = this.$route.query.date;
    IdeaDate({
      date: this.NewDate,
    }).then(({ data }) => {
      this.DateList = data.data.reverse();
      console.log(this.DateList);
    });
  },
  updated() {
    this.GetSwiper();
  },
};
</script>

<style lang="scss" scoped>
.swiper-container {
  width: 90%;
  height: 320px;
  .swiper-wrapper {
    .swiper-slide {
      display: flex;
      align-items: center;
      justify-content: center;
      border-radius: 0.5rem;
      font-size: 22px;
      font-weight: bold;
      color: #333;
      background-color: skyblue;
    }
  }
}
</style>